﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace SS.Ynote.Classic
{
    public class ClipboardHistory : WeifenLuo.WinFormsUI.Docking.DockContent
    {
        #region Constructor

        public ClipboardHistory()
        {
            InitializeComponent();
            Bitmap bmp = SS.Ynote.Classic.Properties.Resources.page_white_paste;
            this.Icon = Icon.FromHandle(bmp.GetHicon());
            this.history.Items.Add(Clipboard.GetText());
            this.Monitor.ClipboardChanged += new EventHandler<ClipboardChangedEventArgs>(Monitor_ClipboardChanged);
        }

        #endregion

        private ClipboardMonitor Monitor;
        private System.Windows.Forms.Panel Panel;
        private LinkLabel linkLabel2;
        private LinkLabel linkLabel1;

        #region Designer

        private AeroListView history;

        private void InitializeComponent()
        {
            this.Panel = new System.Windows.Forms.Panel();
            this.linkLabel2 = new System.Windows.Forms.LinkLabel();
            this.linkLabel1 = new System.Windows.Forms.LinkLabel();
            this.Monitor = new SS.Ynote.Classic.ClipboardMonitor();
            this.history = new SS.Ynote.Classic.AeroListView();
            this.Panel.SuspendLayout();
            this.SuspendLayout();
            // 
            // Panel
            // 
            this.Panel.Controls.Add(this.linkLabel2);
            this.Panel.Controls.Add(this.linkLabel1);
            this.Panel.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.Panel.Location = new System.Drawing.Point(0, 379);
            this.Panel.Name = "Panel";
            this.Panel.Size = new System.Drawing.Size(284, 37);
            this.Panel.TabIndex = 2;
            // 
            // linkLabel2
            // 
            this.linkLabel2.AutoSize = true;
            this.linkLabel2.Location = new System.Drawing.Point(146, 15);
            this.linkLabel2.Name = "linkLabel2";
            this.linkLabel2.Size = new System.Drawing.Size(104, 13);
            this.linkLabel2.TabIndex = 1;
            this.linkLabel2.TabStop = true;
            this.linkLabel2.Text = "Clear Clipboard Data";
            // 
            // linkLabel1
            // 
            this.linkLabel1.AutoSize = true;
            this.linkLabel1.Location = new System.Drawing.Point(12, 15);
            this.linkLabel1.Name = "linkLabel1";
            this.linkLabel1.Size = new System.Drawing.Size(113, 13);
            this.linkLabel1.TabIndex = 0;
            this.linkLabel1.TabStop = true;
            this.linkLabel1.Text = "Clear Clipboard History";
            this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
            // 
            // Monitor
            // 
            this.Monitor.BackColor = System.Drawing.Color.Red;
            this.Monitor.Location = new System.Drawing.Point(0, 30);
            this.Monitor.Name = "Monitor";
            this.Monitor.Size = new System.Drawing.Size(284, 110);
            this.Monitor.TabIndex = 1;
            this.Monitor.Visible = false;
            // 
            // history
            // 
            this.history.Dock = System.Windows.Forms.DockStyle.Fill;
            this.history.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.history.GridLines = true;
            this.history.Location = new System.Drawing.Point(0, 0);
            this.history.Name = "history";
            this.history.Size = new System.Drawing.Size(284, 379);
            this.history.TabIndex = 0;
            this.history.UseCompatibleStateImageBehavior = false;
            this.history.View = System.Windows.Forms.View.List;
            this.history.DoubleClick += new System.EventHandler(this.history_DoubleClick);
            // 
            // ClipboardHistory
            // 
            this.ClientSize = new System.Drawing.Size(284, 416);
            this.Controls.Add(this.Monitor);
            this.Controls.Add(this.history);
            this.Controls.Add(this.Panel);
            this.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Name = "ClipboardHistory";
            this.Text = "Clipboard History";
            this.Panel.ResumeLayout(false);
            this.Panel.PerformLayout();
            this.ResumeLayout(false);

        }
        #endregion

        #region Properties

        FastColoredTextBoxNS.FastColoredTextBox fctb;

       public FastColoredTextBoxNS.FastColoredTextBox TextBox {
            get { return fctb; }
            set { fctb = value; }
        }

        object[] Items = null;

        public object [] HistoryItems {
            get
            {
                return Items;
            }
            set { 
                Items = value; 
            }
        }
        #endregion

        #region Events

        private void Monitor_ClipboardChanged(object sender, ClipboardChangedEventArgs e){
            try { this.history.Items.Add(Clipboard.GetText()); }
            catch (Exception ex) { Console.WriteLine(ex.Message); }
        }

        private void history_DoubleClick(object sender, EventArgs e){
            try{
                this.TextBox.InsertText(this.history.SelectedItems[0].Text);
            }
            catch (Exception ex) { Console.WriteLine(ex.Message); }
        }
        #endregion

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.history.Items.Clear();
      
        }
    }

 
public class AeroListView : ListView
{
 
        [DllImport("uxtheme", CharSet = CharSet.Unicode)]
        public static extern int SetWindowTheme(IntPtr hWnd, string textSubAppName, string textSubIdList);
 
        public AeroListView()
        {
                HandleCreated += AreoListView_HandleCreated;
                this.DoubleBuffered = true;
        }
 
        private void AreoListView_HandleCreated(object sender, System.EventArgs e)
        {
                SetWindowTheme(this.Handle, "explorer", null);
        }
}

}
